jQuery(function ($) {
    $('.page-like').on('click', function () {
        let link = $(this);
        if (link.hasClass('active') || link.find('i').hasClass('fa-heart')) return false;
        let id = $(this).attr('id');
        $.ajax({
            type: 'POST',
            url: '/common/like/' + id,
            dataType: 'json',
            data: {},
            success: function (data) {
                if (data.result.success) {
                    link.addClass('active');
                    link.find('i').attr('class', 'fa fa-heart');
                    let num = parseInt(link.find('.zilla-likes-count').html()) + 1;
                    link.find('.zilla-likes-count').html(num)
                } else {
                    new NoticeJs({
                        text: data.result.error_msg,
                        type: 'warning',
                        position: 'topCenter',
                        progressBar: true,
                        timeout: 30,
                        animation: {
                            open: 'animated fadeIn',
                            close: 'animated fadeOut'
                        }
                    }).show();
                }
            },
        });
        return false;
    });
});
